/**
 * @Title: Pages.java
 * @Package com.ccdt.tvsibp.portal.util
 * @Description: TODO
 * Copyright: Copyright (c) 2018 
 * Company:CCDT
 * 
 * @author xierh
 * @date 2014-3-7 下午4:21:27
 * @version V1.0
 */

package com.zpkj.portal.dto;


/**
 * 分页工具类
 */
public class Page {
	
    private int pageSize = 20;  //一页数据默认20条 
    private int currPage;   //当前页码 
    private int previousPage;   //上一页
    private int nextPage;  //下一页
    private long totalCount;  //一共有多少条数据 
    private int totalPage;  //一共有多少页 
  
    /**
      * 功能：(获取第一条记录位置  )
     */
    public int getFirstResult() {  
        return (this.getCurrPage() - 1) * this.getPageSize();  
    }  
  
   /**
     * 功能：(获取最后记录位置 )
    */
    public int getLastResult() {  
        return this.getCurrPage() * this.getPageSize();  
    }  
  
    /**
      * 功能：( 计算一共多少页 )
     */
    public void setTotalPage() {  
        this.totalPage = (int) ((this.totalCount % this.pageSize > 0) ? (this.totalCount / this.pageSize + 1)  
                : this.totalCount / this.pageSize);  
    }  
  
   /**
     * 功能：(设置 上一页 )
    */
    public void setPreviousPage() {  
        this.previousPage = (this.currPage > 1) ? this.currPage - 1 : this.currPage;  
    }  
  
   /**
     * 功能：(设置下一页 )
    */
    public void setNextPage() {  
        this.nextPage = (this.currPage >= this.totalPage) ? this.currPage : this.currPage + 1;  
    }  
  
    public int getNextPage() {  
        return nextPage;  
    }  
  
    public int getTotalPage() {  
        return totalPage;  
    }  
  
    public int getPreviousPage() {  
        return previousPage;  
    }  
  
    public int getPageSize() {  
        return pageSize;  
    }  
  
    public void setPageSize(int pageSize) {  
        this.pageSize = pageSize;  
    }  
  
  
    public int getCurrPage() {
		return currPage;
	}

	public void setCurrPage(int currPage) {
		this.currPage = currPage;
	}

	public long getTotalCount() {  
        return totalCount;  
    }  
  
    public void setTotalCount(long totalCount2) {  
        this.totalCount = totalCount2;  
    }  
    

    public Page(int currPage, int pageSize, long totalCount) {  
        this.setCurrPage(currPage);  
        this.setPageSize(pageSize);  
        this.setTotalCount(totalCount);  
        this.init();  
    }  
	
    /**
      * 功能：(初始化计算分页 )
     */
    private void init() {  
        this.setTotalPage();// 设置一共页数  
        this.setPreviousPage();// 设置上一页  
        this.setNextPage();// 设置下一页  
    }  
}  
